import { create } from "zustand";
import type { Project } from "../types/projectTypes";
import * as api from '../api/projectsApi';

type ProjectState = {
    projects: Project[];
    pageInfo: { current: number, pageSize: number, total: number };
    loadProjects: (pageNum: number, pageSize: number) => Promise<void>;
}
export const useProjectStore = create<ProjectState>((set) => ({
    projects: [],
    pageInfo: { current: 1, pageSize: 20, total: 0 },
    async loadProjects(pageNum: number, pageSize: number) {
        const data = await api.getProjects(pageNum, pageSize);
        const total = data.headers['x-total']  // 总条数
        set({ projects: data.data, pageInfo: { current: pageNum, pageSize, total } });
    }
}));


